﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Serialization;

namespace WinCustControls
{
    public partial class ParaTextBox : Label
    {
        public ParaTextBox()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 参数点击事件
        /// </summary>
        public event EventHandler DataValClick;

        /// <summary>
        /// 参数值改变事件
        /// </summary>
        public event Action<object, ParaTextBoxArgs> DataValChanged;


        private string _dataVal;
        /// <summary>
        /// 数据值文本
        /// </summary>
        [DefaultValue(typeof(string), "0.0"), Description("数据值文本")]
        public string DataVal
        {
            get { return _dataVal; }
            set
            {
                if (_dataVal != value)
                {
                    _dataVal = value;
                    Text = _dataVal + " " + _unit; // 重绘
                    // 调用DataValChanged事件                                                         
                    DataValChanged?.Invoke(this, new ParaTextBoxArgs(value));
                }

            }
        }

        private string _unit;
        /// <summary>
        /// 单位
        /// </summary>
        [DefaultValue(typeof(string), "m"), Description("单位")]
        public string Unit
        {
            get { return _unit; }
            set
            {
                _unit = value;
                Text = _dataVal + " " + _unit; // 重绘
            }
        }

        private string _varName;
        /// <summary>
        /// 参数名称
        /// </summary>
        [DefaultValue(typeof(string), "VarName"), Description("参数名称")]
        public string VarName
        {
            get { return _varName; }
            set
            {
                _varName = value;
            }
        }

        private void ParaTextBox_Click(object sender, EventArgs args)
        {
            DataValClick?.Invoke(this, new ParaTextBoxArgs(_dataVal));
        }
    }
}
